Skip to content

fix: emit diagnostic for member access on unreduced impl type instead of panicking#9807

Open
orizi wants to merge 1 commit intoorizi/03-31-fix_unsupported_items_in_statement_positionfrom
orizi/03-31-fix_member_access_on_unreduced_impl_type
Open

fix: emit diagnostic for member access on unreduced impl type instead of panicking#9807
orizi wants to merge 1 commit intoorizi/03-31-fix_unsupported_items_in_statement_positionfrom
orizi/03-31-fix_member_access_on_unreduced_impl_type

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 31, 2026

Summary

Replace unreachable panic with proper error handling for member access on unreduced impl associated types. When attempting to access members on ImplType, the code now reports a TypeHasNoMembers diagnostic instead of panicking with an unreachable statement.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The previous implementation would panic with an unreachable statement when encountering member access on unreduced impl associated types (like H::A in generic contexts). This caused the compiler to crash instead of providing a helpful error message to users.


What was the behavior or documentation before?

When accessing members on unreduced impl associated types, the compiler would panic with the message "Impl type should've been reduced" and crash.


What is the behavior or documentation after?

The compiler now gracefully handles this case by reporting error E2057: "Type has no members" with the specific type and member name, allowing compilation to continue and providing better user experience.


Related issue or discussion (if any)

Fixes #9788


Additional context

The change also removes an unused import cairo_lang_debug::DebugWithDb that was only used in the removed unreachable statement. A test case has been added to verify the new error handling behavior works correctly for generic impl associated types.


Note

Medium Risk
Touches core semantic/type-checking code for dot member access; while the change is small, it can affect diagnostics and control flow in the compiler frontend.

Overview
Fixes a crash in semantic expression member access: attempting expr.member on an unreduced impl associated type (TypeLongId::ImplType) now reports TypeHasNoMembers instead of hitting an unreachable! panic.

Cleans up the removed debug-only import usage and adds a new structure test covering H::f(x).val where H::A is still unreduced, asserting error E2057.

Written by Cursor Bugbot for commit 9ff0d29. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Collaborator Author

orizi commented Mar 31, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Copy link
Copy Markdown
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eytan-starkware reviewed 2 files and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on orizi and TomerStarkware).


crates/cairo-lang-semantic/src/expr/compute.rs line 3960 at r1 (raw file):

        TypeLongId::ImplType(_) => Err(ctx.diagnostics.report(
            rhs_syntax.stable_ptr(db),
            TypeHasNoMembers { ty: long_ty.intern(ctx.db), member_name },

Consider an informative error and not just has no members.

@orizi orizi changed the base branch from orizi/03-31-fix_unsupported_items_in_statement_position to graphite-base/9807 April 1, 2026 08:54
@orizi orizi force-pushed the graphite-base/9807 branch from 5b39fa0 to d0640ec Compare April 1, 2026 09:01
@orizi orizi force-pushed the orizi/03-31-fix_member_access_on_unreduced_impl_type branch from 64b11af to ae804b2 Compare April 1, 2026 09:01
Copy link
Copy Markdown
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orizi made 1 comment and resolved 1 discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware and TomerStarkware).


crates/cairo-lang-semantic/src/expr/compute.rs line 3960 at r1 (raw file):

Previously, eytan-starkware wrote…

Consider an informative error and not just has no members.

will consider - but for now less interesting.

@orizi orizi changed the base branch from graphite-base/9807 to orizi/03-31-fix_unsupported_items_in_statement_position April 1, 2026 09:01
@orizi orizi force-pushed the orizi/03-31-fix_unsupported_items_in_statement_position branch from d0640ec to 44fa634 Compare April 1, 2026 09:48
@orizi orizi force-pushed the orizi/03-31-fix_member_access_on_unreduced_impl_type branch from ae804b2 to 9ff0d29 Compare April 1, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants